
import app from "./http";
import rederer from './renderer'
import createStore from './createStore'
import routes from '../share/routes'
import { matchRoutes } from 'react-router-config'

app.get('*',(req,res)=> {
  const store = createStore()
  // 请求地址 req.path
  // 路由信息 routes
  // 根据请求地址匹配出要渲染的组件的路由对象信息
  const promise = matchRoutes(routes,req.path)
  .filter(({route})=>route.loadData)
  .map(({route})=>{
    // 知道数据获取完成
    return route.loadData(store)
  })
  Promise.all(promise).then(()=> {
    res.send(rederer(req,store))
  })
})